#pragma once
#include<iostream>
#include<string>
#include<fstream>
#include<boost/algorithm/string.hpp>
#include "jieba/cppjieba/Jieba.hpp"

using std::cout;
using std::endl;
using std::cerr;
using std::vector; 
using std::string; 

namespace ns_util
{
    class FileUtil
    {
    public:
        static bool ReadFile(const string& file_path,string& out)
        {
            std::ifstream file(file_path,std::ios::in);
            if(file.is_open()==0)//打开路径为file_path的文件
            {
                cerr<<"open fail..."<<endl;
                return false;
            }

            string line;
            while(std::getline(file,line)) out+=line;//虽然getline的返回值类型是istream&，但在底层有强制类型转换，0 or 1

            file.close();

            return true;
        }
    };

    class StringUtil
    {
    public:
        static void CutString(const string& line,vector<string>& results,const string& sep="\3")
        {
            //用boost库中的split函数进行字符串的切割
            boost::split(results,line,boost::is_any_of(sep),boost::token_compress_on);
        }
    };

    // const char* const DICT_PATH="./dict/jieba.dict.utf8";
    // const char* const HMM_PATH="./dict/hmm_model.utf8";
    // const char* const USER_DICT_PATH="./dict/user.dict.utf8";
    // const char* const IDF_PATH="./dict/idf.utf8";
    // const char* const STOP_WORD_PATH="./dict/stop_words.utf8";

    const char* const DICT_PATH = "./dict/jieba.dict.utf8";
    const char* const HMM_PATH = "./dict/hmm_model.utf8";
    const char* const USER_DICT_PATH = "./dict/user.dict.utf8";
    const char* const IDF_PATH = "./dict/idf.utf8";
    const char* const STOP_WORD_PATH = "./dict/stop_words.utf8";
    
    
    class JiebaUtil
    {
    public:
        static void Split(const string& src,vector<string>& out)
        {
            jieba.CutForSearch(src,out);
        }
    private:
        static cppjieba::Jieba jieba;
    };
    cppjieba::Jieba JiebaUtil::jieba(DICT_PATH,HMM_PATH,USER_DICT_PATH,IDF_PATH,STOP_WORD_PATH);
}